<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>数组2</title>
		<script>
			let arr = [5, 7, 10, 12, 30]
			/* 数组元素的求和 */
			/* let sum = 0
			for(let i = 0; i < arr.length; i ++) {
				sum += arr[i]
			}
			console.log(sum) */
			// 形参的第一个：item(a)等同于循环时每个数组元素
			// 形参的第二个：index(b)是循环时的数组索引
			let sum = 0
			arr.forEach((a, b) => {
				sum += a
				console.log('索引：' + b)
			})
			console.log(sum)
		</script>
	</head>
	<body>
	</body>
</html>